﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Ccit.OA.MsPersonDoc;
using Newtonsoft.Json;

namespace Ccit.OA.PersonDoc
{
    public partial class persondoc_space_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Query"] = "";
                PersonDocBLL Bll = new PersonDocBLL();
                Bll.DoOperateSpaceUser();
                Bll = null;
            }
            InitPage();
        }
        private void InitPage()
        {
            ViewState["Query"] = "";
            if (txttName.Text.Trim() != "")
            {
                ViewState["Query"] = " and $$userName$$ like'%" + txttName.Text + "%'";
                ViewState["Query"] += " and $$DeptName$$ like'%" + txttName.Text + "%'";
                ViewState["Query"] += " and $$PostName$$ like'%" + txttName.Text + "%'";
            }
            if(txtArchives.Text.Trim()!="")
            {
                ViewState["Query"] += " and $$Archives$$ " + ddlArchives.SelectedItem.Text + "" + txtArchives.Text + "";
            }
            if (txtAlready.Text.Trim() != "")
            {
                float Already = float.Parse(txtAlready.Text) / 1024 / 1024;
                ViewState["Query"] += " and $$Already$$ " + ddlAlready.SelectedItem.Text + "" + Already + "";
            }
            DataBinde();
        }

        private void DataBinde()
        {
            PersonDocBLL Bll = new PersonDocBLL();
            DataSet dSet = Bll.GetPersonDocSpaceMess(ViewState["Query"].ToString());
            Bll = null;
            if (dSet.Tables[0].Rows.Count > 0)
            {
                dgMain.DataSource = dSet;
            }
            else
            { dgMain.DataSource = null; }
            dgMain.DataBind();
        }

        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            DevExpress.Web.Data.WebDataSelection oSelect = dgMain.Selection;
            oSelect.UnselectAll();
            InitPage();
        }
        #region Ajax Methods
        /// <summary>
        /// get budge 
        /// </summary>
        /// <param name="assetId"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string DoOperate(string strJson)
        {
            List<string> lstResult = new List<string>();
            MsPersonDocSpace ms = new MsPersonDocSpace();
            PersonDocBLL Bll = new PersonDocBLL();
            ms = (MsPersonDocSpace)JavaScriptConvert.DeserializeObject(strJson, typeof(MsPersonDocSpace));
            lstResult = Bll.DoOperateSpace(ms);           
            var newObj = new { message = lstResult[1], resulttype = lstResult[0] };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);
            Bll = null;
            newObj = null;
            return serExpr;
        }
        #endregion
    }
}
